const EventEmitter = require('events');
const http = require('http');


class Sales extends  EventEmitter{
    constructor(){
        super();
    }
}

const myEmitter = new Sales();
myEmitter.on('newSale',()=>{
    console.log('There was a new sale');
})
myEmitter.on('newSale',()=>{
    console.log("Costumer name:jonas");
})

myEmitter.on('newSale',(stock)=>{
    console.log(`There are now ${stock} items left in stock`);
})

myEmitter.emit("newSale",9);

////////////
// 为什么请求了两次
const server = http.createServer();
server.on('request',(req,res)=>{
    console.log('Request received!');
    res.end('Request received');
})

server.on('request',(req,res)=>{
    console.log('Request received!2');
})
server.on('close',(req,res)=>{
    console.log('Request close!');
})

server.listen(8000,"127.0.0.1",()=>{
    console.log("waiting for requests...");
})